package ch03.test.test3;

import org.apache.log4j.Logger;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class SuanfaHandler implements InvocationHandler {
    private Logger logger=Logger.getLogger(SuanfaHandler.class);
    /**
     * 被代理的目标对象
     */
    private Object target;
public void setTarget(Object target){
    this.target=target;
}


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    before();
    Object feedback=method.invoke(target,args);
    after();
        return "查看情况"+feedback;
    }
    public void before(){
        logger.debug("准备计算机。");
    }
    public void after(){
        logger.debug("计算完毕。");
    }
}
